<?php


namespace app\admin\logic;


use app\admin\library\ResultLib;
use app\admin\model\AdminModel;

class AdminLogic
{
    private $model;


    public function __construct()
    {
        $this->model = new AdminModel();
    }


    /**
     * 登陆
     * @param string $username
     * @param string $password
     * @return string
     * @throws \think\db\exception\DataNotFoundException
     * @throws \think\db\exception\ModelNotFoundException
     * @throws \think\exception\DbException
     */
    public function login(string $username, string $password)
    {
        $data = $this->model->where('username', $username)->find();
        if (!$data) {
            return 'NO_EXIST_USER';
        }
        if (!$data->verifyPassword($password)) {
            return 'USER_PASS_ERROR';
        }

        $str = str_pad(mt_rand(0, 999999), 6, '0', STR_PAD_LEFT);
        $str .= $data->uysername;
        $str .= $_SERVER['REQUEST_TIME'];

        $token = md5($str);

        return 'SUCCESS';
    }
}